import numpy as np
from patterns_data import patterns, test_patterns, column_count

def sym_to_digit(s):
    return 1 if s == "O" else -1

def digit_to_sym(n):
    return "O" if n == 1 else " "
    
def np_to_str(arr):
    """
    Transforms a numpy array to a string pattern
    """
    arr = arr.reshape(-1, column_count)
    
    return ["".join(digit_to_sym(digit) for digit in line) for line in arr]

def str_to_np(string):
    """
    Transforms a string pattern to a numpy array
    """
    pattern = tuple(sym_to_digit(symb) for symb in string)
    return np.array(pattern)

#transforms strings pattern from patterns_data to numpy versions
pat = ("".join(p) for p in patterns) # concat de chaque pattern en un string
test_pat = ("".join(p) for p in test_patterns)

learning_patterns = tuple(map(str_to_np, pat))
test_patterns = tuple(map(str_to_np, test_pat))

def pattern_size(patterns):
        return len(patterns[0])


